package com.guo.model.function;

import java.util.*;
import java.util.function.Predicate;

public class VUtils{
    public static ThrowExceptionFunction isTrue(boolean v) {
        return errorMessage -> {
            if(v) {
                throw new RuntimeException(errorMessage);
            }
        };
    }

    public static <T> ThrowExceptionFunction isTrue(Collection<T> c, Predicate<T> predicate) {
        c.forEach(v -> {
            if(predicate.test(v)) {
                throw new RuntimeException("v" + "---exec----");
            }
        });
        return null;
    }

    public static BranchHandle isTrueOrFalse(boolean v) {
        return (trueHandle, falseHandle) -> {
            if(v) {
                trueHandle.run();
            } else {
                falseHandle.run();
            }
        };
    }

    public static PresentOrElseHandle isBlankOrNoBlank(String s) {
        return (consumer, runnable) -> {
            if(!s.isBlank()) {
                consumer.accept(s);
            }else{
                runnable.run();
            }
        };
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>(){
            {
                add("apple");
                add("bonana");
                add("orange");
                add("book");
            }
        };
        isTrue(list, v -> v.equals("book")).throwMessage("book is not fruit...");
    }
}
